package com.reds.backend.controller.article;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.reds.backend.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.reds.backend.service.article.articleGetService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/articleGet")
public class articleGetController {
    @Autowired
    articleGetService articleGetService;

    @PostMapping("/getArticle/")
    public String getArticle(@RequestParam Map<String,String> map){
        System.out.println(map);
        return articleGetService.getArticle(Integer.parseInt(map.get("id")));
    }
    @PostMapping("/isMyArticle/")
    public String isMyArticle(@RequestParam Map<String,String> map){
        return articleGetService.isMyArticle(Integer.parseInt(map.get("id")),map.get("author"));
    }
    @PostMapping("/getArticleByTag/")
    public JSONObject getArticleByTag(@RequestParam Map<String,String> map){
        return articleGetService.getArticleByTag(map.get("tag"),Integer.parseInt(map.get("page")),Integer.parseInt(map.get("sizes")));
    }
    @PostMapping("/divByTag/")
    public List<Article> getArticleByTagHome(@RequestParam Map<String,String> map){
        return articleGetService.getArticleByTagHome(map.get("tag"));
    }
    @PostMapping("/getArticleByAuthor/")
    public JSONObject getArticleByAuthor(@RequestParam Map<String,String> map){
        return articleGetService.getArticleByAuthor(map.get("name"),Integer.parseInt(map.get("page")),Integer.parseInt(map.get("sizes")));
    }
    @PostMapping("/getLatestArtciele/")
    public List<Article> getLatestArtciele(@RequestParam Map<String,String> map){
        return articleGetService.getLatestArticle(Integer.parseInt(map.get("id")));
    }
    @PostMapping("/getRelatedArticle/")
    public List<Article> getRelatedArticle(@RequestParam Map<String,String> map){
        return articleGetService.getRelatedArticle(map.get("tag"),Integer.parseInt(map.get("id")));
    }
    @PostMapping("/nextArticle/")
    public Article nextArticle (@RequestParam Map<String,String> map){
        return articleGetService.nextArticle(Integer.parseInt(map.get("id")),map.get("tag"));
    }
    @PostMapping("/previousArticle/")
    public Article previousArticle (@RequestParam Map<String,String> map){
        return articleGetService.previousArticle(Integer.parseInt(map.get("id")),map.get("tag"));
    }
}
